package com.gamecauca.common;

import com.gamecauca.android.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.ViewGroup.LayoutParams;
import android.widget.ProgressBar;


public class CustomProgressDialog extends Dialog {
	private CustomProgressDialog dialog;
	private String title = null;
	private String message = null;
	private String buttonName;
	private Context mContext;
	private boolean disableButton = false;
	
	public CustomProgressDialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
		this.mContext = context;
		// this.dialog= new
		// CustomProgressDialog(context,R.style.NewDialogProgress);
		disableButton = false;
	}

	public CustomProgressDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.mContext = context;
		// this.dialog= new CustomProgressDialog(context);
		disableButton = false;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void showProgressDialog() {

		dialog = new CustomProgressDialog(this.mContext, R.style.NewDialogProgress);
		dialog.addContentView(new ProgressBar(this.mContext), new LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		//System.out.println("============= SHOW PROGRESS DIALOG ==============");
		if(disableButton){
			dialog.setOnKeyListener(new OnKeyListener() {
				
				@Override
				public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
					// TODO Auto-generated method stub
					if(KeyEvent.ACTION_DOWN == event.getAction()){
						if(KeyEvent.KEYCODE_BACK == event.getKeyCode() || KeyEvent.KEYCODE_SEARCH == event.getKeyCode()){
							return true;
						}
					}
					return false;
				}
			});
		}
		
		dialog.show();

	}

	public void dismissProgressDialog() {
		this.dialog.dismiss();
	}

	public CustomProgressDialog callBack() {

		return this.dialog;
	}

	/**
	 * @param disableButton the disableButton to set
	 */
	public void setDisableButton(boolean disableButton) {
		this.disableButton = disableButton;
	}

}
